package demo2;


class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;

    public TreeNode(int val) {
        this.val = val;

    }

}
public class Solution {
    public TreeNode Convert(TreeNode pRootOfTree) {
        if (pRootOfTree == null) {
            return null;
        }
        ConvertChild(pRootOfTree);
        TreeNode cur = pRootOfTree;
        while (cur.left != null) {
            cur = cur.left;
        }
        return cur;
    }
    TreeNode prev = null;
    public void ConvertChild(TreeNode pCur) {
        if (pCur == null) {
            return;
        }
        ConvertChild(pCur.left);
        pCur.left = prev;
        if (prev != null) {
            prev.right = pCur;
        }
        prev = pCur;
        ConvertChild(pCur.right);
    }
}
